﻿<div ng-controller="Provider_AddC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">仓库添加</h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="form-group">
                                <label>仓库名称（城市+仓库名，例如：广州南沙仓）</label>
                                <input ng-model="providerdata.Name" type="text" class="form-control" required>
                            </div>
                            <div class="form-group">
                                <label>区域</label>
                                <div class="input-group ">
                                    <span class="input-group-addon">省</span>
                                    <select required class="form-control" ng-options="x.FillName for x in items" ng-model="selectedDistrict1"></select>
                                    <span class="input-group-addon">市</span>
                                    <select required class="form-control" ng-options="x as x.Name for x in selectedDistrict1.Children" ng-model="providerdata.District"></select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label>先款优惠(例如：-5)</label>
                                <input ng-model="providerdata.FullPaymentDiscount" type="number" min="0"  class="form-control" required>
                            </div>
                            <div class="form-group">
                                <label>非标优惠(例如：-300)</label>
                                <input ng-model="providerdata.NonstandardDiscount" type="number" min="0"  class="form-control" required>
                            </div>

                            <div class="form-group">
                                <label>区域经理</label>
                                <select required class="form-control" ng-options="x.Name for x in userdata" ng-model="providerdata.Manager"></select>
                            </div>
                            <div class="form-group">
                                <label>驻厂专员</label>
                                <select required class="form-control" ng-options="x.Name for x in userdata" ng-model="providerdata.MainFieldMan"></select>
                            </div>
                            <div class="row text-right">
                                <button type="button" class="btn btn-success" ng-disabled="form.$invalid" ng-click="suppsub()">添加仓库</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    angular.module('app')//非标优惠
        .controller("Provider_AddC", function ($scope, $state, $http, $stateParams) {
            $scope.selectedDistrict1 = "";
            $scope.providerdata = {};
            //获取地市
            $http({
                url:"../api/District",
                method:"GET"
            })
                    .then(function (res) {
                        $scope.items = res.data;
                    })
                    .then(function (error) {
                        if(error){
                            console.log("error");
                        }
                    });
            //获取人员
            $http({
                url: "../api/Employee/List?name=&page=1&rows=9999",
                method:"GET"
            })
                    .then(function (res) {
                        $scope.userdata = res.data.Data;
                    })
                    .then(function (error) {
                        if(error){
                            console.log("error");
                        }
                    });
//            提交信息
            $scope.suppsub = function(){
                console.log($scope.providerdata);
                $http.post('../api/Provider', $scope.providerdata)
                        .success(function (res) {
                            if (res.State <= 0) {
                                alert(res.Msg);
                            } else {
                                alert("添加成功");
                                $state.go('app.Provider_List');
                            }

                        });
            };
        })
</script>